package io.mft.datasource.mq.rabbitmq.producer;

import java.util.HashMap;

/**
 * 消息发送者
 * @说明： TODO
 * @类型名称：MessageSender
 * @创建者 ： 杨亮
 * @创建时间： 2019/11/10  10:14
 * @修改者 ： 杨亮
 * @修改时间： 2019/11/10  10:14
 */
public class MessageSender {


    // 异步发送
    public static void sendMessageString( final String msg, String exchangeId ,final MessageSendCallBack<String> messageSendCallBack) {
        sendMessageBean(msg, exchangeId, messageSendCallBack);
    }

    // 异步发送
    public static void sendMessageMap(HashMap<String,Object> msg, String exchangeId , MessageSendCallBack<HashMap> messageSendCallBack) {
        sendMessageBean(msg, exchangeId, messageSendCallBack);
    }

    // 异步发送
    public static <T> void sendMessageBean(T msgObject, String exchangeId , MessageSendCallBack<T> messageSendCallBack) {
    	/**
        String connectionName = MqManager.getInstance().getConnectionBeanName( exchangeId ) ;
        if (ObjectUtil.isEmpty(connectionName)){
            throw new RuntimeException("没有找到注册连接");
        }
        String exchangeName =  MqManager.getInstance().getExchangeName(exchangeId) ;
        if (ObjectUtil.isEmpty(exchangeName)){
            throw new RuntimeException("没有找到交换机");
        }
        byte[] msgByte = null ;
        if (msgObject instanceof byte[]){
            msgByte = (byte[])msgObject ;
        } else {
            if (msgObject instanceof String){
                msgByte =  ((String) msgObject).getBytes();
            }else {
                msgByte = JSONUtil.toJsonStr(msgObject).getBytes();
            }
        }
        Integer version=1;
        		//PluginFunction.THREADLOCAL_VERSION.get();
       // if (version==null) {
        //	 throw new RuntimeException("未获取业务版本，请检查当前执行线程是否是业务中间件调用线程");
		//}
        ConnectionFactory connectionFactory = MFTSpringUtil.getApplicationContext(Thread.currentThread().getContextClassLoader()).getBean( connectionName, ConnectionFactory.class );
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setMessageId("message_id:"+UUID.randomUUID().toString());
        Message m =   new Message( msgByte ,messageProperties  ) ;
        
        logger.debug("exchange>>>>"+ exchangeName );
        new MqRabbitTemplate(connectionFactory, messageSendCallBack ,msgObject).convertAndSend( exchangeName  , null,  m);
        return ;
        **/
    }

public static void main(String[] args) {
	String vvString="140008";
	Object ooObject=vvString.getBytes();
	System.out.println();
}

}
